#!/bin/bash

mkdir -p /opt
pushd /opt
tar xzf /tmp/gating_repo.tar.gz
rm /tmp/gating_repo.tar.gz

for file in /etc/yum.repos.d/*.repo; do
    sed -i 's/priority=2/priority=3/' $file;
    sed -i 's/priority=1/priority=2/' $file;
done

cat > /etc/yum.repos.d/gating.repo << EOF
[gating-repo]
name=Gating repository
baseurl=file:///opt/gating_repo
enabled={{ gating_repo_enabled | bool | ternary('1', '0') }}
gpgcheck=0
priority=1
EOF

{% if gating_repo_enabled|bool %}
{{ ansible_pkg_mgr }} --disablerepo="*" --enablerepo="gating-repo" update -y
{% endif %}
